home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Un ejercicio de presentación de texto / SysInfoUpdate / SysInfoUpdate.cs next >
Encoding:
Text File  |  2002-05-16  |  2.5 KB  |  80 lines

  1. //--------------------------------------------
  2. // SysInfoUpdate.cs ⌐ 2001 by Charles Petzold
  3. //--------------------------------------------
  4. using Microsoft.Win32;
  5. using System;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8.  
  9. class SysInfoUpdate: Form
  10. {
  11.      protected int      iCount;
  12.      protected string[] astrLabels;
  13.      protected string[] astrValues;
  14.      protected float    cxCol;
  15.      protected int      cySpace;
  16.  
  17.      public static void Main()
  18.      {
  19.           Application.Run(new SysInfoUpdate());
  20.      }
  21.      public SysInfoUpdate()
  22.      {
  23.           Text = "Informaci≤n del Sistema: Actualizaci≤n";
  24.           BackColor = SystemColors.Window;
  25.           ForeColor = SystemColors.WindowText;
  26.           AutoScroll = true;
  27.      
  28.           SystemEvents.UserPreferenceChanged += 
  29.                new UserPreferenceChangedEventHandler(UserPreferenceChanged);
  30.  
  31.           SystemEvents.DisplaySettingsChanged +=
  32.                new EventHandler(DisplaySettingsChanged);
  33.  
  34.           UpdateAllInfo();
  35.      }
  36.      void UserPreferenceChanged(object obj, UserPreferenceChangedEventArgs ea)
  37.      {
  38.           UpdateAllInfo();
  39.           Invalidate();
  40.      }
  41.      void DisplaySettingsChanged(object obj, EventArgs ea)
  42.      {
  43.           UpdateAllInfo();         
  44.           Invalidate();
  45.      }
  46.      void UpdateAllInfo()
  47.      {
  48.           iCount     = SysInfoStrings.Count;
  49.           astrLabels = SysInfoStrings.Labels;
  50.           astrValues = SysInfoStrings.Values;
  51.  
  52.           Graphics grfx  = CreateGraphics();
  53.           SizeF    sizef = grfx.MeasureString(" ", Font);
  54.           cxCol = sizef.Width + SysInfoStrings.MaxLabelWidth(grfx, Font);
  55.           cySpace = Font.Height;
  56.  
  57.           AutoScrollMinSize = new Size(
  58.               (int) Math.Ceiling(cxCol + 
  59.                                  SysInfoStrings.MaxValueWidth(grfx, Font)),
  60.               (int) Math.Ceiling(cySpace * iCount));
  61.  
  62.           grfx.Dispose();
  63.      }
  64.      protected override void OnPaint(PaintEventArgs pea)
  65.      {
  66.           Graphics grfx  = pea.Graphics;
  67.           Brush    brush = new SolidBrush(ForeColor);
  68.           Point    pt    = AutoScrollPosition;
  69.  
  70.           for (int i = 0; i < iCount; i++)
  71.           {
  72.                grfx.DrawString(astrLabels[i], Font, brush, 
  73.                                pt.X, pt.Y + i * cySpace);
  74.  
  75.                grfx.DrawString(astrValues[i], Font, brush, 
  76.                                pt.X + cxCol, pt.Y + i * cySpace); 
  77.           }
  78.      }
  79. }
  80.